package cn.kgc.service.impl;

import cn.kgc.mapper.UserMapper;
import cn.kgc.model.PageWrapper;
import cn.kgc.model.User;
import cn.kgc.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author Rock
 * @create 2020-08-25 17:05
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired(required = false)
    private UserMapper userMapper;

    @Override
    public User selectUserById(Integer id) {
        return userMapper.selectUserById(id);
    }

    @Override
    public List<User> selectUserList() {
        List<User> users = userMapper.selectUserList();
        return users;
    }

    @Override
    public PageWrapper selectUserList(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<User> userList = userMapper.selectUserList();
        PageInfo<User> pageInfo = new PageInfo<>(userList);
        return new PageWrapper(pageInfo.getTotal(), userList);
    }

    @Override
    public Boolean updateUserMoney(Map map1, Map map2) {
        Integer integer1 = userMapper.updateUserMoney(map1);
        int i = 3 / 0; //模拟异常
        Integer integer2 = userMapper.updateUserMoney(map2);
        return 0 != integer1 && 0 != integer2;
    }
}